<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>23-转换为数字型</title>
    <script>
        // var age = prompt('请输入你的年龄:')
        // // 1. parseInt(变量) 可以帮字符型转换为数字型
        // console.log(parseInt(age));
        console.log(parseInt('3.14')); //3 取整
        console.log(parseInt('3.94')); //3 取整
        console.log(parseInt('120px')); //120 取整 会去掉px单位
        console.log(parseInt('rem120px')); //NaN
        // 2. parseFloat(变量) 浮点数
        console.log(parseFloat('3.14')); //3.14
        console.log(parseFloat('120px')); //120
        console.log(parseFloat('rem120px')); //NaN

        //3. 利用Number(变量)
        console.log(Number('12'));
        //4. 利用当地算数运算 - * / 隐式转换
        console.log('12' - 0);//12
        console.log('123' - '120');//数字3
        console.log('123' * 1);//数字3
    </script>
</head>

<body>
    <img src="./images/int.PNG" alt="">
</body>

</html>